home *** CD-ROM | disk | FTP | other *** search
- Path: newsserv.zdv.uni-tuebingen.de!news
- From: hans.loeffler@student.uni-tuebingen.de
- Newsgroups: comp.lang.c++
- Subject: Q: Pointer to member fctn within member fctn
- Date: Fri, 09 Feb 1996 20:18:14 GMT
- Organization: InterNetNews at ZDV Uni-Tuebingen
- Message-ID: <4fgab1$h27@newsserv.zdv.uni-tuebingen.de>
- Reply-To: hans.loeffler@student.uni-tuebingen.de
- NNTP-Posting-Host: zxmkp12.extern.uni-tuebingen.de
- X-Newsreader: Forte Free Agent 1.0.82
-
- I have a problem calling a member function through a pointer within
- another member function
- Consider:
-
- typedef void (*pmfctn)(int); //pointer to member function
-
- class X {
- void f1(int);
- void f2(int);
-
- pmfctn pf1, pf2;
-
- void f3(pmfctn);
- };
-
- void X::f1(void) {
- // do something
- ...
- return;
- }
- ...
-
- void X::f3(pmfctn pf) {
-
- int a = 5;
- // I want to call f1 or f2 now
- // problem here:
- this->*pf(a); // **
- }
- // ** this results in a runtime error with Borland C++ V4.5, when
- calling f3(pf1) or f3(pf2)
- // I initialize pf1 as:
- pf1 = &X::f1;
-
- In books I only saw things like
-
- X *px;
-
- px->*pf1(a);
- which call the functions from an object and not within a member
- function
-
- What is wrong with my solution?
-
- Hans
-
-